//
//  STDoorInfoVC.m
//  YiYueHairdresser
//
//  Created by zhouzhouzhou on 2018/10/9.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STDoorInfoVC.h"
#import "STHairerInfoVC.h"
#import "ChatViewController.h"

#import "STDoorInfoView.h"
#import "STOrderFooter1View.h"

#import "STMainPageService.h"

@interface STDoorInfoVC ()<STDoorInfoViewDelete,STOrderFooter1ViewDelegate>{
    UIButton * doorLikeBtn;
    STDoorInfoView * doorInfoView;
}
@property (nonatomic,strong) STDoorApplyStatusModel *statusModel;
@property (nonatomic,strong)STOrderFooter1View * bottomView;
@end

@implementation STDoorInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"门店";
    [self wr_setNavBarTintColor:[UIColor blackColor]];
    
    doorLikeBtn =[[UIButton alloc]init];
    [doorLikeBtn setImage:[UIImage imageNamed:@"c-selLike"] forState:UIControlStateNormal];
    [doorLikeBtn setImage:[UIImage imageNamed:@"c-cancellike"] forState:UIControlStateSelected];
    [doorLikeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    doorLikeBtn.frame=CGRectMake(0, 0, 30, 30);
    [doorLikeBtn addTarget:self action:@selector(actionLikeDoor) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * likeBarBtn = [[UIBarButtonItem alloc]initWithCustomView:doorLikeBtn];
    
    UIButton * shareBtn =[[UIButton alloc]init];
    [shareBtn setImage:[UIImage imageNamed:@"c-share"] forState:UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    shareBtn.frame=CGRectMake(0, 0, 30, 30);
    [shareBtn addTarget:self action:@selector(actionShareDoor) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * shareBarBtn = [[UIBarButtonItem alloc]initWithCustomView:shareBtn];
    
    self.navigationItem.rightBarButtonItems =@[shareBarBtn,likeBarBtn];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self loadDoorInfoData];
    [self loadDoorInfoView:nil];
    [self loadDoorFooterView];
    
}

- (void)actionShareDoor{
    
}

- (void)actionLikeDoor{
    
}

- (void)loadDoorInfoData{

    // nexus 0-签约 1-入驻
    [STMainPageService getDoorInfoWithParameters:@{@"Token":@"token",@"storeId":@(_stylistId),@"nexus":[NSNumber numberWithBool:self.isSign]} completion:^(id result, NSError *error) {
        //TODO:判断获取不到数据 处理方式
        if (error) {
            [ZYHCommonMethod showError:error];
        }
        STDoorInfoModel *doorInfo = [STDoorInfoModel modelWithJSON:result];
        [self loadDoorInfoView:doorInfo];
//        doorLikeBtn.selected = doorInfo.localInfo.isCollection;
        
        // 设置底部状态
        [self disPlayBottomViewStatu:result];
    }];
}

-(void)disPlayBottomViewStatu:(id)result
{
    // 底部申请状态
    id obj = [result objectForKey:@"getNexuStatus"];
    self.statusModel = [STDoorApplyStatusModel modelWithJSON:obj];
    // 申请状态 0 未申请 1 申请中 2 成功 3 未通过 ,
    if ([self.statusModel.applyStatus isEqualToString:@"0"]) {
        [self.bottomView.agreeBtn setTitle:@"申请入驻" forState:UIControlStateNormal];
    }else if ([self.statusModel.applyStatus isEqualToString:@"1"]){
        [self.bottomView.agreeBtn setTitle:@"申请中" forState:UIControlStateNormal];
    }else if ([self.statusModel.applyStatus isEqualToString:@"2"]){
        [self.bottomView.agreeBtn setTitle:@"解约" forState:UIControlStateNormal];
    }else{
        [self.bottomView.agreeBtn setTitle:@"未通过" forState:UIControlStateNormal];
    }
}

- (void)loadDoorInfoView:(STDoorInfoModel *)model
{
    if (doorInfoView == nil) {
        doorInfoView = [[STDoorInfoView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-50)];
        doorInfoView.delegate = self;
        [doorInfoView setShopInViewWithData:nil];
        [self.view addSubview:doorInfoView];
    }else{
        [doorInfoView setShopInViewWithData:model];
    }
}

- (void)loadDoorFooterView{
    STOrderFooter1View * doorFooterView = [[STOrderFooter1View alloc]initWithFrame: CGRectMake(0, SCREEN_HEIGHT-64-50, SCREEN_WIDTH, 50)];
    doorFooterView.backgroundColor = [UIColor whiteColor];
    [doorFooterView setOrderFooterViewWithType:1 data:nil];
    doorFooterView.priceView.hidden = YES;
    doorFooterView.communicateView.hidden = NO;
    doorFooterView.communicateView.backgroundColor = [UIColor whiteColor];
    [doorFooterView.msgBtn setTitle:@"咨询" forState:UIControlStateNormal];
    doorFooterView.refuseBtn.hidden = YES;
    doorFooterView.agreeBtn.backgroundColor = ButtonBackColor;
//    if (self.isSign) {
//        [doorFooterView.agreeBtn setTitle:@"解约" forState:UIControlStateNormal];
//    }else{
//        [doorFooterView.agreeBtn setTitle:@"申请签约" forState:UIControlStateNormal];
//    }
    
    doorFooterView.footerDelegate = self;
    [self.view addSubview:doorFooterView];
    [doorFooterView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    self.bottomView = doorFooterView;
}
#pragma mark - 底部点击事件
-(void)orderFooter1ViewWithActionType:(STOrderFooter1ViewActionType)actionType orderType:(int)orderType{
    if (actionType == msgBtnAction) {
        if (YLIsStringEmpty(self.statusModel.userIMName)) {
            [YLProgressHUDManager showMessage:@"会话ID为空" duration:0.5];return;
        }
        ChatViewController *chatController = [[ChatViewController alloc] initWithConversationChatter:self.statusModel.userIMName?:@"" conversationType:EMConversationTypeChat];
        chatController.title = self.statusModel.userIMName?:@"";
        [self.navigationController pushViewController:chatController animated:YES];
    }
}

-(void)doorInfoViewSeeMoreHair{
    
}

-(void)doorInfoViewSelHairDic:(int)hairNum{
    STHairerInfoVC * hairInfoVC  =[STHairerInfoVC new];
    hairInfoVC.stylistId = 1;
    hairInfoVC.hidesBottomBarWhenPushed= YES;
    [self.navigationController pushViewController:hairInfoVC animated:YES];
}

@end
